#ifndef __TOYM__NET__POLLERS__EPOLLER_H__
#define __TOYM__NET__POLLERS__EPOLLER_H__

#include "net/Pollers/IPoller.h"
#include <unordered_map>

// 前置声明
struct epoll_event;

namespace toym
{
namespace net
{

class EPoller: public IPoller {
public:
    EPoller();
    ~EPoller();

    virtual int poll() override;
    virtual void updateChannel(Channel& channel) override;
    virtual void removeChannel(Channel& channel) override;
    virtual std::vector<Channel*> getActiveChannels(int nActive) override;
private:
    void update(int mode, Channel& channel);

    int m_epollfd;
    std::unordered_map<int, Channel*> m_fd2Channel;
    std::vector<struct epoll_event> m_events;

    static const int s_New = -1;
    static const int s_Deleted = 0;
    static const int s_Added = 1;
};

} // namespace net

} // namespace toym


#endif // __TOYM__NET__POLLERS__EPOLLER_H__